package jfqemu;

/**
 * Created : Mar 19, 2012
 *
 * @author pquiring
 */

import java.awt.*;
import java.io.*;
import javax.swing.*;

import javaforce.*;

public class VMDialog extends javax.swing.JDialog {

  /**
   * Creates new form VMDialog
   */
  public VMDialog(java.awt.Frame parent, boolean modal, VM vm) {
    super(parent, modal);
    initComponents();
    setPosition();
    listTAPs();
    this.vm = vm;
    if (vm == null) return;
    name.setText(vm.name);
    folder.setText(vm.folder);
    folder.setEditable(false);
    os.setSelectedItem(vm.os);
    hda.setText(vm.hda);
    hdb.setText(vm.hdb);
    hdc.setText(vm.hdc);
    hdd.setText(vm.hdd);
    hdacd.setSelected(vm.hdacd);
    hdbcd.setSelected(vm.hdbcd);
    hdccd.setSelected(vm.hdccd);
    hddcd.setSelected(vm.hddcd);

    if (vm.hdaif == null) vm.hdaif = "IDE";
    hdaif.setSelectedItem(vm.hdaif);
    if (vm.hdbif == null) vm.hdbif = "IDE";
    hdbif.setSelectedItem(vm.hdbif);
    if (vm.hdcif == null) vm.hdcif = "IDE";
    hdcif.setSelectedItem(vm.hdcif);
    if (vm.hddif == null) vm.hddif = "IDE";
    hddif.setSelectedItem(vm.hddif);

    cpuCount.setValue(new Integer(vm.cpuCount));
    x64.setSelected(vm.cpuType.equals("x86_64"));
    memory.setText("" + vm.memory);
    if (vm.boot.equals("c"))
      boot.setSelectedIndex(0);
    else
      boot.setSelectedIndex(1);
    if (vm.serviceID != -1) {
      isService.setSelected(true);
      serviceID.setValue(new Integer(vm.serviceID));
    }
    sound.setSelectedItem(vm.sound);
    video.setSelectedItem(vm.video);
    if (vm.net1model == null) vm.net1model = "disabled";
    net1model.setSelectedItem(vm.net1model);
    if (vm.net1type == null) vm.net1type = "user";
    net1type.setSelectedItem(vm.net1type);
    if (vm.net2model == null) vm.net2model = "disabled";
    net2model.setSelectedItem(vm.net2model);
    if (vm.net2type == null) vm.net2type = "user";
    net2type.setSelectedItem(vm.net2type);
    if (vm.net3model == null) vm.net3model = "disabled";
    net3model.setSelectedItem(vm.net3model);
    if (vm.net3type == null) vm.net3type = "user";
    net3type.setSelectedItem(vm.net3type);
    usb.setSelected(vm.usb);
    if (JF.isWindows()) {
      tabs.remove(serviceTab);
    }
    if (vm.chipset == null) vm.chipset = "PIIX3";  //or PIIX4 ???
    chipset.setSelectedItem(vm.chipset);
  }

  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    name = new javax.swing.JTextField();
    os = new javax.swing.JComboBox();
    accept = new javax.swing.JButton();
    cancel = new javax.swing.JButton();
    jLabel10 = new javax.swing.JLabel();
    folder = new javax.swing.JTextField();
    tabs = new javax.swing.JTabbedPane();
    drivesTab = new javax.swing.JPanel();
    hddcd = new javax.swing.JCheckBox();
    hdbcd = new javax.swing.JCheckBox();
    hda = new javax.swing.JTextField();
    hd2new = new javax.swing.JButton();
    hdccd = new javax.swing.JCheckBox();
    hdc = new javax.swing.JTextField();
    jLabel6 = new javax.swing.JLabel();
    hdacd = new javax.swing.JCheckBox();
    jLabel4 = new javax.swing.JLabel();
    hdb = new javax.swing.JTextField();
    hdsselect = new javax.swing.JButton();
    hd2select = new javax.swing.JButton();
    hdd = new javax.swing.JTextField();
    hd3new = new javax.swing.JButton();
    jLabel3 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    hd4select = new javax.swing.JButton();
    hd1select = new javax.swing.JButton();
    hd4new = new javax.swing.JButton();
    hd1new = new javax.swing.JButton();
    jLabel18 = new javax.swing.JLabel();
    hdaif = new javax.swing.JComboBox();
    hdbif = new javax.swing.JComboBox();
    hdcif = new javax.swing.JComboBox();
    hddif = new javax.swing.JComboBox();
    optionsTab = new javax.swing.JPanel();
    jLabel9 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    cpuCount = new javax.swing.JSpinner();
    jLabel7 = new javax.swing.JLabel();
    boot = new javax.swing.JComboBox();
    memory = new javax.swing.JTextField();
    x64 = new javax.swing.JCheckBox();
    jLabel22 = new javax.swing.JLabel();
    chipset = new javax.swing.JComboBox();
    hwTab = new javax.swing.JPanel();
    jLabel11 = new javax.swing.JLabel();
    video = new javax.swing.JComboBox();
    jLabel12 = new javax.swing.JLabel();
    sound = new javax.swing.JComboBox();
    jLabel13 = new javax.swing.JLabel();
    net1model = new javax.swing.JComboBox();
    usb = new javax.swing.JCheckBox();
    jLabel16 = new javax.swing.JLabel();
    net1type = new javax.swing.JComboBox();
    net2model = new javax.swing.JComboBox();
    jLabel15 = new javax.swing.JLabel();
    jLabel19 = new javax.swing.JLabel();
    net2type = new javax.swing.JComboBox();
    net3model = new javax.swing.JComboBox();
    jLabel20 = new javax.swing.JLabel();
    jLabel21 = new javax.swing.JLabel();
    net3type = new javax.swing.JComboBox();
    serviceTab = new javax.swing.JPanel();
    isService = new javax.swing.JCheckBox();
    serviceID = new javax.swing.JSpinner();
    jLabel14 = new javax.swing.JLabel();
    jLabel17 = new javax.swing.JLabel();
    jLabel23 = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("VM");

    jLabel1.setText("Name:");

    jLabel2.setText("OS:");

    name.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyReleased(java.awt.event.KeyEvent evt) {
        nameKeyReleased(evt);
      }
    });

    os.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Windows", "Linux", "Other" }));

    accept.setText("Accept");
    accept.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        acceptActionPerformed(evt);
      }
    });

    cancel.setText("Cancel");
    cancel.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        cancelActionPerformed(evt);
      }
    });

    jLabel10.setText("Folder:");

    hddcd.setText("CD-ROM");

    hdbcd.setText("CD-ROM");

    hd2new.setText("New...");
    hd2new.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        hd2newActionPerformed(evt);
      }
    });

    hdccd.setText("CD-ROM");

    jLabel6.setText("HD4");

    hdacd.setText("CD-ROM");

    jLabel4.setText("HD2");

    hdsselect.setText("Select...");
    hdsselect.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        hdsselectActionPerformed(evt);
      }
    });

    hd2select.setText("Select...");
    hd2select.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        hd2selectActionPerformed(evt);
      }
    });

    hd3new.setText("New...");
    hd3new.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        hd3newActionPerformed(evt);
      }
    });

    jLabel3.setText("HD1");

    jLabel5.setText("HD3");

    hd4select.setText("Select...");
    hd4select.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        hd4selectActionPerformed(evt);
      }
    });

    hd1select.setText("Select...");
    hd1select.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        hd1selectActionPerformed(evt);
      }
    });

    hd4new.setText("New...");
    hd4new.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        hd4newActionPerformed(evt);
      }
    });

    hd1new.setText("New...");
    hd1new.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        hd1newActionPerformed(evt);
      }
    });

    jLabel18.setText("NOTE : Use /dev/cdrom for physical CD-ROM");

    hdaif.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "IDE", "SCSI", "SATA" }));

    hdbif.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "IDE", "SCSI", "SATA" }));

    hdcif.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "IDE", "SCSI", "SATA" }));

    hddif.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "IDE", "SCSI", "SATA" }));

    javax.swing.GroupLayout drivesTabLayout = new javax.swing.GroupLayout(drivesTab);
    drivesTab.setLayout(drivesTabLayout);
    drivesTabLayout.setHorizontalGroup(
      drivesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(drivesTabLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(drivesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(drivesTabLayout.createSequentialGroup()
            .addGroup(drivesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(drivesTabLayout.createSequentialGroup()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hdd, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hddif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hd4select))
              .addGroup(drivesTabLayout.createSequentialGroup()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hda)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hdaif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hd1select)))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(drivesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(hd1new)
              .addComponent(hd4new, javax.swing.GroupLayout.Alignment.TRAILING))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(drivesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(hdacd)
              .addComponent(hddcd, javax.swing.GroupLayout.Alignment.TRAILING)))
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, drivesTabLayout.createSequentialGroup()
            .addComponent(jLabel4)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(hdb)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(hdbif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(hd2select)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(hd2new)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(hdbcd))
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, drivesTabLayout.createSequentialGroup()
            .addComponent(jLabel5)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(hdc)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(hdcif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(hdsselect)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(hd3new)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(hdccd))
          .addGroup(drivesTabLayout.createSequentialGroup()
            .addComponent(jLabel18)
            .addGap(0, 0, Short.MAX_VALUE)))
        .addContainerGap())
    );
    drivesTabLayout.setVerticalGroup(
      drivesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(drivesTabLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(drivesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel3)
          .addComponent(hda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(hd1select)
          .addComponent(hd1new)
          .addComponent(hdacd)
          .addComponent(hdaif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(drivesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel4)
          .addComponent(hdb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(hd2select)
          .addComponent(hd2new)
          .addComponent(hdbcd)
          .addComponent(hdbif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(drivesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel5)
          .addComponent(hdc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(hdsselect)
          .addComponent(hd3new)
          .addComponent(hdccd)
          .addComponent(hdcif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(drivesTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel6)
          .addComponent(hdd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(hd4select)
          .addComponent(hd4new)
          .addComponent(hddcd)
          .addComponent(hddif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jLabel18)
        .addContainerGap())
    );

    tabs.addTab("Drives", drivesTab);

    jLabel9.setText("Memory (MBs)");

    jLabel8.setText("# CPUs:");

    cpuCount.setModel(new javax.swing.SpinnerNumberModel(1, 1, 8, 1));
    cpuCount.setValue(new Integer(1));

    jLabel7.setText("1st Boot Device:");

    boot.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Hard Drive", "CD-ROM" }));

    memory.setText("256");

    x64.setText("64bit");

    jLabel22.setText("Chipset");

    chipset.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PIIX3", "ICH9" }));

    javax.swing.GroupLayout optionsTabLayout = new javax.swing.GroupLayout(optionsTab);
    optionsTab.setLayout(optionsTabLayout);
    optionsTabLayout.setHorizontalGroup(
      optionsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(optionsTabLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(optionsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(optionsTabLayout.createSequentialGroup()
            .addComponent(jLabel7)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(boot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGroup(optionsTabLayout.createSequentialGroup()
            .addComponent(jLabel8)
            .addGap(18, 18, 18)
            .addComponent(cpuCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(x64))
          .addGroup(optionsTabLayout.createSequentialGroup()
            .addComponent(jLabel9)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(memory, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGroup(optionsTabLayout.createSequentialGroup()
            .addComponent(jLabel22)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(chipset, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addContainerGap(364, Short.MAX_VALUE))
    );
    optionsTabLayout.setVerticalGroup(
      optionsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(optionsTabLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(optionsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel7)
          .addComponent(boot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(optionsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel8)
          .addComponent(cpuCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(x64))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(optionsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel9)
          .addComponent(memory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(optionsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel22)
          .addComponent(chipset, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap(61, Short.MAX_VALUE))
    );

    tabs.addTab("Options", optionsTab);

    jLabel11.setText("Video");

    video.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "cirrus", "std", "vmware", "qxl" }));

    jLabel12.setText("Sound");

    sound.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "none", "sb16", "es1370", "ac97", "hda", "all" }));

    jLabel13.setText("Network1");

    net1model.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "disabled", "e1000", "lance", "i82551", "i82557b", "i82559er", "ne2k_pci", "ne2k_isa", "pcnet", "rtl8139", "smc91c111", "mcf_fec" }));

    usb.setText("USB");

    jLabel16.setText("Type:");

    net1type.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "user" }));

    net2model.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "disabled", "e1000", "lance", "i82551", "i82557b", "i82559er", "ne2k_pci", "ne2k_isa", "pcnet", "rtl8139", "smc91c111", "mcf_fec" }));

    jLabel15.setText("Network2");

    jLabel19.setText("Type:");

    net2type.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "user" }));

    net3model.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "disabled", "e1000", "lance", "i82551", "i82557b", "i82559er", "ne2k_pci", "ne2k_isa", "pcnet", "rtl8139", "smc91c111", "mcf_fec" }));

    jLabel20.setText("Network3");

    jLabel21.setText("Type:");

    net3type.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "user" }));

    javax.swing.GroupLayout hwTabLayout = new javax.swing.GroupLayout(hwTab);
    hwTab.setLayout(hwTabLayout);
    hwTabLayout.setHorizontalGroup(
      hwTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(hwTabLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(hwTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(hwTabLayout.createSequentialGroup()
            .addGroup(hwTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jLabel11)
              .addComponent(jLabel12))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(hwTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(sound, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGroup(hwTabLayout.createSequentialGroup()
                .addComponent(video, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(usb))))
          .addGroup(hwTabLayout.createSequentialGroup()
            .addComponent(jLabel13)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(net1model, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jLabel16)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(net1type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGroup(hwTabLayout.createSequentialGroup()
            .addComponent(jLabel15)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(net2model, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jLabel19)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(net2type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGroup(hwTabLayout.createSequentialGroup()
            .addComponent(jLabel20)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(net3model, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jLabel21)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(net3type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addContainerGap(284, Short.MAX_VALUE))
    );
    hwTabLayout.setVerticalGroup(
      hwTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(hwTabLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(hwTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel11)
          .addComponent(video, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(usb))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(hwTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel12)
          .addComponent(sound, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(hwTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel13)
          .addComponent(net1model, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel16)
          .addComponent(net1type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(hwTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel15)
          .addComponent(net2model, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel19)
          .addComponent(net2type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(hwTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel20)
          .addComponent(net3model, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel21)
          .addComponent(net3type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap(15, Short.MAX_VALUE))
    );

    tabs.addTab("Hardware", hwTab);

    isService.setText("Run as a Service");

    serviceID.setModel(new javax.swing.SpinnerNumberModel(1, 1, 99, 1));

    jLabel14.setText("Unique Service ID");
    jLabel14.setToolTipText("This is used as the VNC port (TCP)");

    jLabel17.setText("(1-99)");

    javax.swing.GroupLayout serviceTabLayout = new javax.swing.GroupLayout(serviceTab);
    serviceTab.setLayout(serviceTabLayout);
    serviceTabLayout.setHorizontalGroup(
      serviceTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(serviceTabLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(serviceTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(isService)
          .addGroup(serviceTabLayout.createSequentialGroup()
            .addComponent(jLabel14)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(serviceID, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jLabel17)))
        .addContainerGap(303, Short.MAX_VALUE))
    );
    serviceTabLayout.setVerticalGroup(
      serviceTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(serviceTabLayout.createSequentialGroup()
        .addContainerGap()
        .addComponent(isService)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(serviceTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(serviceID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel14)
          .addComponent(jLabel17))
        .addContainerGap(118, Short.MAX_VALUE))
    );

    tabs.addTab("Service", serviceTab);

    jLabel23.setText("Status:");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(tabs, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
          .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jLabel1)
              .addComponent(jLabel2))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(os, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(name)))
          .addGroup(layout.createSequentialGroup()
            .addComponent(jLabel10)
            .addGap(8, 8, 8)
            .addComponent(folder))
          .addGroup(layout.createSequentialGroup()
            .addComponent(jLabel23, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(cancel)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(accept)
            .addGap(0, 0, Short.MAX_VALUE)))
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel1)
          .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel10)
          .addComponent(folder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel2)
          .addComponent(os, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(tabs)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(accept)
          .addComponent(cancel)
          .addComponent(jLabel23))
        .addContainerGap())
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
    dispose();
  }//GEN-LAST:event_cancelActionPerformed

  private void acceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptActionPerformed
    if (!valid()) return;
    accepted = true;
    File folderFile = new File(folder.getText());
    folderFile.mkdirs();
    dispose();
  }//GEN-LAST:event_acceptActionPerformed

  private void nameKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nameKeyReleased
    if (vm != null) return;
    folder.setText(JF.getUserPath() + "/jfqemu/" + name.getText().replaceAll(" ", ""));
  }//GEN-LAST:event_nameKeyReleased

  private void hd1newActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hd1newActionPerformed
    newImage(hda, 'a');
  }//GEN-LAST:event_hd1newActionPerformed

  private void hd1selectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hd1selectActionPerformed
    selectImage(hda);
  }//GEN-LAST:event_hd1selectActionPerformed

  private void hd2newActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hd2newActionPerformed
    newImage(hdb, 'b');
  }//GEN-LAST:event_hd2newActionPerformed

  private void hd2selectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hd2selectActionPerformed
    selectImage(hdb);
  }//GEN-LAST:event_hd2selectActionPerformed

  private void hd3newActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hd3newActionPerformed
    newImage(hdc, 'c');
  }//GEN-LAST:event_hd3newActionPerformed

  private void hdsselectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hdsselectActionPerformed
    selectImage(hdc);
  }//GEN-LAST:event_hdsselectActionPerformed

  private void hd4newActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hd4newActionPerformed
    newImage(hdd, 'd');
  }//GEN-LAST:event_hd4newActionPerformed

  private void hd4selectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hd4selectActionPerformed
    selectImage(hdd);
  }//GEN-LAST:event_hd4selectActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton accept;
  private javax.swing.JComboBox boot;
  private javax.swing.JButton cancel;
  private javax.swing.JComboBox chipset;
  private javax.swing.JSpinner cpuCount;
  private javax.swing.JPanel drivesTab;
  private javax.swing.JTextField folder;
  private javax.swing.JButton hd1new;
  private javax.swing.JButton hd1select;
  private javax.swing.JButton hd2new;
  private javax.swing.JButton hd2select;
  private javax.swing.JButton hd3new;
  private javax.swing.JButton hd4new;
  private javax.swing.JButton hd4select;
  private javax.swing.JTextField hda;
  private javax.swing.JCheckBox hdacd;
  private javax.swing.JComboBox hdaif;
  private javax.swing.JTextField hdb;
  private javax.swing.JCheckBox hdbcd;
  private javax.swing.JComboBox hdbif;
  private javax.swing.JTextField hdc;
  private javax.swing.JCheckBox hdccd;
  private javax.swing.JComboBox hdcif;
  private javax.swing.JTextField hdd;
  private javax.swing.JCheckBox hddcd;
  private javax.swing.JComboBox hddif;
  private javax.swing.JButton hdsselect;
  private javax.swing.JPanel hwTab;
  private javax.swing.JCheckBox isService;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel10;
  private javax.swing.JLabel jLabel11;
  private javax.swing.JLabel jLabel12;
  private javax.swing.JLabel jLabel13;
  private javax.swing.JLabel jLabel14;
  private javax.swing.JLabel jLabel15;
  private javax.swing.JLabel jLabel16;
  private javax.swing.JLabel jLabel17;
  private javax.swing.JLabel jLabel18;
  private javax.swing.JLabel jLabel19;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel20;
  private javax.swing.JLabel jLabel21;
  private javax.swing.JLabel jLabel22;
  private javax.swing.JLabel jLabel23;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel6;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel8;
  private javax.swing.JLabel jLabel9;
  private javax.swing.JTextField memory;
  private javax.swing.JTextField name;
  private javax.swing.JComboBox net1model;
  private javax.swing.JComboBox net1type;
  private javax.swing.JComboBox net2model;
  private javax.swing.JComboBox net2type;
  private javax.swing.JComboBox net3model;
  private javax.swing.JComboBox net3type;
  private javax.swing.JPanel optionsTab;
  private javax.swing.JComboBox os;
  private javax.swing.JSpinner serviceID;
  private javax.swing.JPanel serviceTab;
  private javax.swing.JComboBox sound;
  private javax.swing.JTabbedPane tabs;
  private javax.swing.JCheckBox usb;
  private javax.swing.JComboBox video;
  private javax.swing.JCheckBox x64;
  // End of variables declaration//GEN-END:variables

  public boolean accepted = false;
  private VM vm;

  public void getValues(VM vm) {
    vm.name = name.getText();
    vm.folder = folder.getText();
    vm.os = (String)os.getSelectedItem();
    vm.hda = hda.getText();
    vm.hdb = hdb.getText();
    vm.hdc = hdc.getText();
    vm.hdd = hdd.getText();
    vm.hdacd = hdacd.isSelected();
    vm.hdbcd = hdbcd.isSelected();
    vm.hdccd = hdccd.isSelected();
    vm.hddcd = hddcd.isSelected();
    vm.hdaif = (String)hdaif.getSelectedItem();
    vm.hdbif = (String)hdbif.getSelectedItem();
    vm.hdcif = (String)hdcif.getSelectedItem();
    vm.hddif = (String)hddif.getSelectedItem();
    vm.cpuCount = (Integer)cpuCount.getValue();
    vm.cpuType = x64.isSelected() ? "x86_64" : "i386";
    vm.memory = JF.atoi(memory.getText());
    switch (boot.getSelectedIndex()) {
      case 0: vm.boot = "c"; break;
      case 1: vm.boot = "d"; break;
    }
    if (isService.isSelected())
      vm.serviceID = (Integer)serviceID.getValue();
    else
      vm.serviceID = -1;
    vm.sound = (String)sound.getSelectedItem();
    vm.video = (String)video.getSelectedItem();
    vm.net1model = (String)net1model.getSelectedItem();
    vm.net1type = (String)net1type.getSelectedItem();
    vm.net2model = (String)net2model.getSelectedItem();
    vm.net2type = (String)net2type.getSelectedItem();
    vm.net3model = (String)net3model.getSelectedItem();
    vm.net3type = (String)net3type.getSelectedItem();
    vm.usb = usb.isSelected();
    vm.chipset = (String)chipset.getSelectedItem();
  }

  private boolean isNumberValid(JTextField tf, int min, int max) {
    tf.setBackground(new Color(0xff0000));
    String str = tf.getText();
    int value = JF.atoi(str);
    if ((min != -1) && (value < min)) return false;
    if ((max != -1) && (value > max)) return false;
    tf.setBackground(new Color(0xffffff));
    return true;
  }

  private boolean isNumberValid(JSpinner sp, int min, int max) {
    sp.setBackground(new Color(0xff0000));
    int value = (Integer)sp.getValue();
    if ((min != -1) && (value < min)) return false;
    if ((max != -1) && (value > max)) return false;
    sp.setBackground(new Color(0xffffff));
    return true;
  }

  private boolean valid() {
    boolean ok = true;
    if (!isNumberValid(cpuCount, 1, 8)) ok = false;
    if (!isNumberValid(memory, 64, -1)) ok = false;
    File newFile = new File(folder.getText() + "/jfqemu.xml");
    if ( ((vm == null) && newFile.exists()) || (name.getText().length() == 0) ) {
      //VM already exists or name is empty
      name.setBackground(Color.red);
      ok = false;
    } else {
      name.setBackground(Color.white);
    }
    if (isService.isSelected()) {
      //make sure service ID is unique
      boolean idok = true;
      int id = (Integer)serviceID.getValue();
      for(int a=0;a<MainPanel.vms.size();a++) {
        VM vm = MainPanel.vms.get(a);
        if (vm == this.vm) continue;
        if (id == vm.serviceID) {
          idok = ok = false;
          serviceID.setBackground(Color.red);
        }
      }
      if (idok) serviceID.setBackground(Color.white);
    }
    return ok;
  }

  private void newImage(JTextField hd, char idx) {
    String initFilename = folder.getText() + "/hd" + idx;
    NewImageDialog dialog = new NewImageDialog(null, true, initFilename);
    dialog.setVisible(true);
    if (!dialog.accepted) return;
    String qemuimg = "";
    if (JF.isWindows()) {
      qemuimg += System.getenv("ProgramFiles");
      qemuimg += "\\QEMU\\";
    }
    qemuimg += "qemu-img";
    String cmd[] = {qemuimg, "create", "-f", dialog.getImageType()
      , dialog.getFilename(), dialog.getImageSize() + "G"};
    try {
      File folderFile = new File(folder.getText());
      folderFile.mkdirs();
      Runtime.getRuntime().exec(cmd);
    } catch(Exception e) {
      JFAWT.showError("Error", "Failed to execute qemu-img");
      JFLog.log(e);
    }
    hd.setText(dialog.getFilename());
  }

  private void selectImage(JTextField hd) {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setCurrentDirectory(new File(JF.getCurrentPath()));
    if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return;
    hd.setText(chooser.getSelectedFile().getAbsolutePath());
  }

  private void listTAPs() {
    net1type.removeAllItems();
    net1type.addItem("user");
    net2type.removeAllItems();
    net2type.addItem("user");
    net3type.removeAllItems();
    net3type.addItem("user");
    if (JF.isWindows()) return;  //TODO : support Windows ???
    ShellProcess sp = new ShellProcess();
    String output = sp.run(new String[] {"ifconfig", "-a"}, false);
    String lns[] = output.split("\n");
    for(int a=0;a<lns.length;a++) {
      if (!lns[a].startsWith(" ")) {
        int idx = lns[a].indexOf(" ");
        if (idx == -1) continue;
        String name = lns[a].substring(0,idx);
        if (!name.startsWith("tap")) continue;
        net1type.addItem(name);
        net2type.addItem(name);
        net3type.addItem(name);
      }
    }
    net1type.setSelectedIndex(0);
    net2type.setSelectedIndex(0);
    net3type.setSelectedIndex(0);
  }

  private void setPosition() {
    Rectangle s = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    Dimension d = getPreferredSize();
    setLocation(s.width/2 - d.width/2, s.height/2 - (d.height/2));
  }
}
